<?php

namespace app\admin\controller;
/**
 * Class Company
 * @package app\admin\controller
 *
 * CREATE TABLE `tp_company` (
`id` SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
`lang` VARCHAR(20) NOT NULL DEFAULT 'zh-cn' COMMENT '语言',
`title` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '标题',
`username` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '发布人',
`uid` SMALLINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'uid',
`center` TEXT NOT NULL COMMENT '内容',
`status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`sort` INT(11) NOT NULL,
`deleteTime` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '回收站',
`create_time` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新时间',
`url` VARCHAR(500) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM
ROW_FORMAT=DYNAMIC
AUTO_INCREMENT=2
;

 */
class Company extends base
{

    //前置方法
    protected $beforeActionList = [
        'map'  =>  ['only'=>'index'],
    ];

    /**
     * 搜索
     */
    protected function map(){
        if ($this->request->isGet()) {
            $data = $this->request->param();
            $this->datas = array();
            if (!empty($data['start_time']) && !empty($data['end_time']) && (strtotime($data['start_time']) < strtotime($data['end_time']))) {
                $this->datas ['create_time'] = [
                    ['>', strtotime($data['start_time'])],
                    ['<', strtotime($data['end_time'])]
                ];
            }
            $this->datas['lang'] = cookie('think_var_admin');
        }
    }


    /**
     * 保存
     */
    public function save()
    {
        if (!$this->request->isPost()) {
            return ajax_info('请求失败');
        }
        $data = $this->request->post();

        if(!empty($data['id'])){
           return $this->update($data);
        }
        $data['lang']=cookie('think_var_admin');

        $res = $this->model->allowField(true)->save($data);
        if ($res) {
            return ajax_info('保存成功','y');
        } else {
            return ajax_info('添加失败');
        }
    }
}
